<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>jQuery contextMenu Plugin</title>
    <meta name="description" content="simple contextMenu generator for interactive web applications based on jQuery" />
    
    <script src="jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="prettify/prettify.js" type="text/javascript"></script>
    <script src="screen.js" type="text/javascript"></script>
    <link href="screen.css" rel="stylesheet" type="text/css" />
    <link href="prettify/prettify.sunburst.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-8922143-3']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
</head>
<body>
    <a id="github-forkme" href="https://github.com/medialize/jQuery-contextMenu"><img src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
    <div id="container">
    <h1><a href="https://github.com/medialize/jQuery-contextMenu">jQuery contextMenu</a></h1>
    
    <ul class="menu">
        <li><a href="index.html">About</a></li>
        <li><a href="demo.html">Demo</a></li>
        <li class="active"><a href="docs.html">Documentation</a></li>
        <li><a href="http://rodneyrehm.de/en/">Author</a></li>
    </ul>
    
    <ul class="toc">
        <li>
            <a href="#register">Register new contextMenu</a>
            <ul>
                <li><a href="#options">options (at registration)</a></li>
                <li><a href="#items">options.items</a></li>
                <li><a href="#opt">opt (options at runtime)</a></li>
                <li><a href="#types">Custom Command Types</a></li>
            </ul>
        </li>
        <li><a href="#disable-trigger">Disable a contextMenu trigger</a></li>
        <li><a href="#enable-trigger">Enable a contextMenu trigger</a></li>
        <li><a href="#show-trigger">Manually show a contextMenu</a></li>
        <li><a href="#hide-trigger">Manually hide a contextMenu</a></li>
        <li><a href="#unregister-contextMenu">Unregister contextMenu</a></li>
        <li><a href="#unregister-all">Unregister all contextMenus</a></li>
        <li><a href="#helper-import-values">Helper: Import values for &lt;input&gt;</a></li>
        <li><a href="#helper-export-values">Helper: Export values from &lt;input&gt;</a></li>
        <li><a href="#events">Events</a></li>
        <li><a href="#html5-import">HTML5 &lt;menu&gt; import</a></li>
        <li><a href="#html5-shiv">HTML5 &lt;menu&gt; shiv/polyfill</a></li>
        <li><a href="#ui-position">$.ui.position</a></li>
    </ul>

    <h2 id="register">Register new contextMenu</h2>
    <p>To register a new contextMenu:</p>
    <pre class="prettyprint lang-js">$.contextMenu( options );</pre>
    
    <h3 id="options">options (at registration)</h3>
    
    <dl>
        <dt id="options-selector"><em>(string)</em> selector</dt>
        <dd>
            <p>No Default Value - specification is Mandatory</p>
            <p>The selector matching the trigger objects.</p>
            <p>Example: <code>"span.with-context"</code>.</p>
        </dd>
        
        <dt id="options-items"><em>(object)</em> items</dt>
        <dd>
            <p>No Default Value - specification is Mandatory</p>
            <p>Items to be listed in contextMenu. See <a href="#items">Items</a>.</p>
            <p>Example: <code>{ one: {name: "one", callback: function(key, opt){ alert("Clicked on " + key); } }}</code></p>
        </dd>
        
        <dt id="options-appendTo"><em>(selector | DOMElement)</em> appendTo</dt>
        <dd>
            <p>default: document.body</p>
            <p>Specifies the DOMElement the generated menu is to be appended to</p>
            <p>Example: <code>"#context-menus-container"</code>.</p>
        </dd>
        
        <dt id="options-trigger"><em>(string)</em> trigger</dt>
        <dd>
            <p>default: <em>"right"</em></p>
            <p>Specifies the event to show the contextMenu</p>
            <p>Possible values: "right", "left", "hover", "none"</p>
        </dd>
        
        <dt id="options-reposition"><em>(boolean)</em> reposition</dt>
        <dd>
            <p>
                Specifies if a menu should be repositioned (true) or rebuilt (false) if a second trigger event (like a right click) is performed
                on the same trigger element (or its children) while the menu is still visible.
            </p>
        </dd>
        
        <dt id="options-delay"><em>(int)</em> delay</dt>
        <dd>
            <p>default: <em>200</em></p>
            <p>Specifies the time in milliseconds to wait before showing the menu. Only applies to <code>trigger: "hover"</code></p>
        </dd>
        
        <dt id="options-autohide"><em>(boolean)</em> autoHide</dt>
        <dd>
            <p>default: <em>false</em></p>
            <p>Specifies if the menu must be hidden when the mouse pointer is moved out of the trigger and menu elements</p>
        </dd>
        
        <dt id="options-zIndex"><em>(int)</em> zIndex</dt>
        <dd>
            <p>default: <em>1</em></p>
            <p>Specifies the offset to add to the calculated zIndex of the trigger element. Set to <em>0</em> to prevent zIndex manipulation</p>
        </dd>
        
        <dt id="options-className"><em>(string)</em> className</dt>
        <dd>
            <p>Specifies additional classNames to add to the menu element</p>
        </dd>
        
        <dt id="options-animation"><em>(object)</em> animation</dt>
        <dd>
            <p>default: <em>{duration: 500, show: "slideDown", hide: "slideUp"}</em></p>
            <p>
                animation properties take effect on showing and hiding the menu. 
                <em>duration</em> specifies the duration of the animation in milliseconds.
                <em>show</em> and <em>hide</em> specify jQuery methods to show and hide elements.
            </p>
            <p>Possible show and hide animations: <code>{show: "show", hide: "hide"}</code>, <code>{show: "fadeIn", hide: "fadeOut"}, …</code>
        </dd>
        
        <dt id="options-events"><em>(object)</em> events</dt>
        <dd>
            <p>The show and hide events are triggered before the menu is shown or hidden.</p>
            <p>The event handlers are executed in the context of the triggering object. <em>this</em> will thus reference the jQuery handle of the trigger object.</p>
            <p>A reference to the current <a href="#opt">options</a> object is passed</p>
            <p>The event handlers may return <em>false</em> to prevent the show or hide process.</p>
            <p>Example: <code>{show: function(opt){ this.addClass('currently-showing-menu'); alert("Selector: " + opt.selector); }}</code></p>
        </dd>
        
        <dt id="options-position"><em>(function)</em> position</dt>
        <dd>
            <p>Position the context menu.</p>
            <p>The function is executed in the context of the trigger object.</p>
            <p>The first argument ist the <em>$menu</em> jQuery object</p>
            <p>The second and third arguments are <em>x</em> and <em>y</em> coordinates provided by the showing event</p>
            <p><em>x</em> and <em>y</em> may either be integers denoting the offset from the top left corner, undefined, or the string "maintain". If the string "maintain" is provided, the current position of the <em>$menu</em> must be used. If the coordinates are undefined, appropriate coordinates must be determined. An example of how this can be achieved is provided with <a href="#options-determinePosition">determinePosition</a>.</p>
            <p>Example: <code>{position: function($menu, x, y){$menu.css({top: 123, left: 123});}}</code></p>
        </dd>
        
        <dt id="options-determinePosition"><em>(function)</em> determinePosition</dt>
        <dd>
            <p>Determine the position of the menu in respect to the given trigger object.</p>
            <p>Hint: <a href="http://docs.jquery.com/UI/Position">jQuery UI's position()</a> may ease things up.</p>
            <p>Example: <code>$menu.css('display', 'block').position({ my: "center top", at: "center bottom", of: this, offset: "0 5"}).css('display', 'none');</code></p>
        </dd>
        
        <dt id="options-callback"><em>(function)</em> callback</dt>
        <dd>
            <p>Specifies the default callback to be used in case an item does not expose its own callback.</p>
            <p>The default callback behaves just like <a href="#items-callback">item.callback</a>.</p>
            <p>Example: <code>{callback: callback: function(key, opt){ alert("Clicked on " + key + " on element " + opt.$trigger.attr("id")); }}</code></p>
        </dd>
        
        <dt id="options-build"><em>(function)</em> build</dt>
        <dd>
            <p>Callback that's supposed to return the <em>options</em> object on demand</p>
            <p>The callback is executed with two arguments given: the jQuery reference to the triggering element and the original contextemnu event. 
                It is executed without context (so this won't refer to anything useful).</p>
            <p>If the <em>build</em> callback is found at registration, the menu is not built right away. The menu creation is delayed to the point where the menu is actually called to show. Dynamic menus don't stay in the DOM. After a menu created with <em>build</em> is hidden, its DOM-footprint is destroyed.</p>
            <p>With <em>build</em>, only the options <a href="#options-selector">selector</a> and <a href="#options-trigger">trigger</a> may be specified in the
                options object. All other options need to be returned from the <em>build</em> callback.</p>
            <p>the <em>build</em> callback may return a boolean <em>false</em> to signal contextMenu to not display a context menu</p>
            <pre class="prettyprint lang-js">{selector: ".awesome-menu",
build: function($trigger, e){
  return {
    callback: function(){},
    items: {
        foo: {name: "Foo"}
    }
  };
}};</pre>
        </dd>
    </dl>
    
    <h3 id="items">options.items</h3>
    <p>The <em>items</em> map contains the commands to list in the menu. Each command has a unique key identifying an item object. The value may either be an item (properties explained below), or a string (which will insert a separator, disregarding the string's content).</p>
    <pre class="prettyprint lang-js">var items = {
  command1: commandOptions,
  separator1: "-----",
  command2: commandOptions
}</pre>
    
    <dl>
        <dt id="items-name"><em>(string)</em> name</dt>
        <dd>
            <p>Specified the human readable name of the command in the menu</p>
            <p>This is a mandatory property</p>
        </dd>

        <dt id="items-callback"><em>(function)</em> callback</dt>
        <dd>
            <p>Specifies the callback to execute if clicked on</p>
            <p>
                The Callback is executed in the context of the triggering object.
                The first argument is the <em>key</em> of the command.
                The second argument is the <a href="#opt">options</a> object.
                The Callback may return <em>false</em> to prevent the menu from being hidden.
            </p>
            <p>Example: <code>{ command1: {name: "Foobar", callback: function(key, opt){ alert("Clicked on " + key + " on element " + opt.$trigger.id); } }}</code></p>
            <p>If no callback and no <a href="#options-callback">default callback</a> is specified, the item will not have an action</p>
        </dd>

        <dt id="items-className"><em>(string)</em> className</dt>
        <dd>
            <p>Specifies additional classNames to add to the item element</p>
        </dd>
        
        <dt id="items-icon"><em>(string)</em> icon</dt>
        <dd>
            <p>Specifies the icon class to set for the item.</p>
            <p>Icons must be defined in CSS with selectors like <code>.context-menu-item.icon-<em>edit</em></code>, where <em>edit</em> is the icon class.</p>
        </dd>
        
        <dt id="items-disabled"><em>(function|boolean)</em> disabled</dt>
        <dd>
            <p>Specifies if the command is disabled (<em>true</em>) or enabled (<em>false</em>).</p>
            <p>
                May be a callback returning a boolean. 
                The Callback is executed in the context of the triggering object (so <code>this</code> inside the function refers to the element the context menu was shown for).
                The first argument is the <em>key</em> of the command.
                The second argument is the <a href="#opt">options</a> object. 
            </p>
            <p>Example: { command1: {name: "Foobar", callback: function(key, opt){ return true; } }}</p>
        </dd>
        
        <dt id="items-type"><em>(string)</em> type</dt>
        <dd>
            <p>Specifies the type of the command.</p>
            <p><em>null</em>, <em>undefined</em> and the <em>empty-string</em> make the command a simple clickable item.</p>
            <p><em>"text"</em> makes the command an &lt;input&gt; of type text. The name followed by the &lt;input&gt; are encapsulated in a &lt;label&gt;.</p>
            <p><em>"textarea"</em> makes the command a &lt;textarea&gt;. The name followed by the &lt;input&gt; are encapsulated in a &lt;label&gt;.</p>
            <p><em>"checkbox"</em> makes the command an &lt;input&gt; of type checkbox. The name preceeded by the &lt;input&gt; are encapsulated in a &lt;label&gt;. The checkbox-element is moved to the icon space</p>
            <p><em>"radio"</em> makes the command an &lt;input&gt; of type radio. The name preceeded by the &lt;input&gt; are encapsulated in a &lt;label&gt;. The radio-element is moved to the icon space</p>
            <p><em>"select"</em> makes the command a &lt;select&gt;. The name followed by the &lt;select&gt; are encapsulated in a &lt;label&gt;.</p>
            <p><em>"html"</em> makes an non-command element.</p>
        </dd>
        
        <dt id="items-events"><em>(object)</em> events</dt>
        <dd>
            <p>Events to register on &lt;input&gt; elements</p>
            <p>Only used with <a href="#items-type">types</a> <em>"text"</em>, <em>"textarea"</em>, <em>"radio"</em>, <em>"checkbox"</em> and <em>"select"</em>.</p>
            <p>Example: { command1: {name: "Foobar", type: "text", events: {keyup: function(e){alert(e.keyCode);}} }}</p>
            <p>The contents of the options object are passed to jQuery event.data.</p>
            <p>Example: { command1: {name: "Foobar", type: "text", events: {keyup: function(e){alert(e.data.$trigger.attr("id"));}} }}</p>
        </dd>

        <dt id="items-value"><em>(string)</em> value</dt>
        <dd>
            <p>The value of the &lt;input&gt; element.</p>
            <p>Only used with <a href="#items-type">types</a> <em>"text"</em>, <em>"textarea"</em> and <em>"radio"</em>.</p>
        </dd>

        <dt id="items-selected"><em>(string|boolean)</em> selected</dt>
        <dd>
            <p>The selected option of a &lt;select&gt; element and the checked property for <em>"checkbox"</em> and <em>"radio"</em> types.</p>
            <p>Expecting a boolean when used with <a href="#items-type">types</a> <em>"checkbox"</em> and <em>"radio"</em>.</p>
            <p>Expecting a string when used with <a href="#items-type">type</a> <em>"select"</em></p>
        </dd>

        <dt id="items-radio"><em>(string)</em> radio</dt>
        <dd>
            <p>Specifies the group of the radio elements.</p>
            <p>Only used with <a href="#items-type">type</a> <em>"radio"</em>.</p>
        </dd>

        <dt id="items-options"><em>(object)</em> options</dt>
        <dd>
            <p>Specifies the &lt;option&gt;s for the &lt;select&gt; element.</p>
            <p>Only used with <a href="#items-type">type</a> <em>"select"</em>.</p>
            <p>Example: <code>{name: "select box", selected: "two", options: {one: "red", two: "blue", three: "green"}}</code></p>
        </dd>
        
        <dt id="items-height"><em>(int)</em> height</dt>
        <dd>
            <p>The height in pixel &lt;textarea&gt; element. If not specified, the height is defined by CSS.</p>
            <p>Only used with <a href="#items-type">type</a> <em>"textarea"</em>.</p>
        </dd>
        
        <dt id="items-items"><em>(object)</em> items</dt>
        <dd>
            <p>Commands to show in a sub-menu.</p>
        </dd>
        
        <dt id="items-accesskey"><em>(string)</em> accesskey</dt>
        <dd>
            <p>Character(s) to be used as accesskey.</p>
            <p>
                Considering »a b c« $.contextMenu will first try to use »a« as the accesskey, if already taken, it'll fall through to »b«. 
                Words are reduced to the first character, so »hello world« is treated as »h w«.
            </p>
            <p>
                Note: Accesskeys are treated unique throughout one menu. This means an item in a sub-menu can't 
                occupy the same accesskey as an item in the main menu.
            </p>
        </dd>
        
        <dt id="items-node"><em>(jQuery)</em> $node</dt>
        <dd>
            <p>Reference to the &lt;li&gt; command element</p>
            <p>created by contextMenu on registration</p>
        </dd>
        
        <dt id="items-input"><em>(jQuery)</em> $input</dt>
        <dd>
            <p>Reference to the &lt;input&gt; or &lt;select&gt; of the command element.</p>
            <p>Only available with <a href="#items-type">type</a> <em>"text"</em>, <em>"textarea"</em>, <em>"checkbox"</em>, <em>"radio"</em> and <em>"select"</em>.</p>
            <p>created by contextMenu on registration</p>
        </dd>
        
        <dt id="items-label"><em>(jQuery)</em> $label</dt>
        <dd>
            <p>Reference to the &lt;label&gt; of the command element</p>
            <p>Only available with <a href="#items-type">type</a> <em>"text"</em>, <em>"textarea"</em>, <em>"checkbox"</em>, <em>"radio"</em> and <em>"select"</em>.</p>
            <p>created by contextMenu on registration</p>
        </dd>
        
        <dt id="items-node"><em>(jQuery)</em> $menu</dt>
        <dd>
            <p>Reference to the &lt;ul&gt; sub-menu element</p>
            <p>created by contextMenu on registration</p>
        </dd>
    </dl>
    
    
    <h3 id="opt">opt (options at runtime)</h3>
    <p><em>opt</em> is a reference to the <em>options</em> object passed at contextMenu registration</p>
    <dl>
        <dt id="opt-trigger"><em>(jQuery)</em> $trigger</dt>
        <dd>
            <p>The element triggering the menu</p>
        </dd>
        
        <dt id="opt-menu"><em>(jQuery)</em> $menu</dt>
        <dd>
            <p>The menu element</p>
        </dd>
        
        <dt id="opt-callbacks"><em>(object)</em> callbacks</dt>
        <dd>
            <p>Registered callbacks of all commands (including those of sub-menus)</p>
        </dd>
        
        <dt id="opt-commands"><em>(object)</em> commands</dt>
        <dd>
            <p>Registered commands (including those of sub-menus)</p>
        </dd>
        
        <dt id="opt-inputs"><em>(object)</em> inputs</dt>
        <dd>
            <p>Registered commands of input-type (including those of sub-menus)</p>
            <p>Access a specific &lt;input&gt;: <code>opt.inputs[key].$input</code></p>
        </dd>
        
        <dt id="opt-hasTypes"><em>(boolean)</em> hasTypes</dt>
        <dd>
            <p>flag denoting if the menu contains input elements</p>
        </dd>
        
        <dt id="opt-ns"><em>(string)</em> ns</dt>
        <dd>
            <p>The namespace (including leading dot) all events for this contextMenu instance were registered under</p>
        </dd>
    </dl>
    
    <h3 id="types">Custom Command Types</h3>
    <p>Besides the built-in <a href="#items-type">command types</a> custom handlers can be defined. 
        The command generator must be placed in <code>$.contextMenu.types</code>. It is identified
        by the key given in that object. The generator function is executed in the context of the
        new command's &lt;li&gt; within the menu. <code>item</code> is the object passed at creation. 
        Use this to pass values from your definition to the generator. <code>opt</code> is the current
        menu level, <code>root</code> is the menu's root-level <code>opt</code> (relevant for sub-menus only).
    </p>
    <p>
        A custom command type can be whatever you like it to be, it can behave how ever you want it to behave. 
        Besides the keyboard interaction paradigm  (up, down, tab, escape) key-events are passed on to the 
        &lt;li&gt; which can be accessed via <code>$(this).on('keydown', …);</code>
    </p>
    <p>
        Note that you'll probably want to disable default action handling (click, pressing enter) in favor of
        the custom command's behavior.
    </p>
    <pre class="prettyprint lang-js">$.contextMenu.types.myType = function(item, opt, root) {
    $('&lt;span&gt;' + item.customName + '&lt;/span&gt;').appendTo(this);
    this.on('contextmenu:focus', function(e) {
        // setup some awesome stuff
    }).on('contextmenu:blur', function(e) {
        // tear down whatever you did
    }).on('keydown', function(e) {
        // some funky key handling, maybe?
    });
};
$.contextMenu({
    selector: '.context-menu-custom', 
    items: {
        label: {type: "myType", customName: "Foo Bar"}
    }
});</pre>
    
    
    
    <h2 id="disable-trigger">Disable a contextMenu trigger</h2>
    <p>disable contextMenu to be shown on specified trigger elements</p>
    <pre class="prettyprint lang-js">$(".some-selector").contextMenu(false);</pre>
    
    <h2 id="enable-trigger">Enable a contextMenu trigger</h2>
    <p>enable contextMenu to be shown on specified trigger elements</p>
    <pre class="prettyprint lang-js">$(".some-selector").contextMenu(true);</pre>
    
    <h2 id="show-trigger">Manually show a contextMenu</h2>
    <p>show the contextMenu of the first element of the selector (position determined by <a href="#options-determinePosition">determinePosition</a>):</p>
    <pre class="prettyprint lang-js">$(".some-selector").contextMenu();</pre>
    <pre class="prettyprint lang-js">$(".some-selector").contextMenu({x: 123, y: 123});</pre>
    
    <h2 id="hide-trigger">Manually hide a contextMenu</h2>
    <p>hide the contextMenu of the first element of the selector:</p>
    <pre class="prettyprint lang-js">$(".some-selector").contextMenu("hide");</pre>
    
    <h2 id="unregister-contextMenu">Unregister contextMenu</h2>
    <p>To unregister / destroy a specific contextMenu:</p>
    <pre class="prettyprint lang-js">$.contextMenu( 'destroy', <em>selector</em> );</pre>
    <p><em>selector</em> expects the (string) selector that the contextMenu was registered to</p>
    
    <h2 id="unregister-all">Unregister all contextMenus</h2>
    <p>To unregister / destroy all contextMenus:</p>
    <pre class="prettyprint lang-js">$.contextMenu( 'destroy' );</pre>

    <h2 id="helper-import-values">Helper: Import values for &lt;input&gt;</h2>
    <p>To fill input commands with values from a map:</p>
    <pre class="prettyprint lang-js">{events: {
    hide: function(opt){ 
      $.contextMenu.getInputValues(opt, {command1: "foo", command2: "bar"}); 
    }
  }
}</pre>
    <p>To fill input commands with values from data-attributes:</p>
    <pre class="prettyprint lang-js">{events: {
  hide: function(opt){ 
    $.contextMenu.getInputValues(opt, this.data());
    }
  }
}</pre>

    <h2 id="helper-export-values">Helper: Export values from &lt;input&gt;</h2>
    <p>To fetch values from input commands:</p>
    <pre class="prettyprint lang-js">{events: {
  hide: function(opt){ 
    var values = $.contextMenu.setInputValues(opt}
  }
}</pre>
    <p>To save values from input commands to data-attributes:</p>
    <pre class="prettyprint lang-js">{events: {
  hide: function(opt){ 
    $.contextMenu.setInputValues(opt, this.data()); }
  }
}</pre>
    
    
    <h2 id="events">Events</h2>
    <dl>
        <dt>contextmenu</dt>
        <dd>
            <p>Trigger context menu to be shown for a trigger object.</p>
            <p>Available on <em>trigger object</em>. The Event must be supplied with coordinates for the menu: <code>{pageX: 123, pageY:123}</code></p>
            <pre class="prettyprint lang-js">$('.context-menu-one').first().trigger(
  $.Event('contextmenu', {pageX: 123, pageY: 123})
);</pre>
            <pre class="prettyprint lang-js">$('.context-menu-one').first().trigger("contextmenu");</pre> 
            <p>will invoke <a href="#options-determinePosition">determinePosition</a> to position the menu</p>
        </dd>
        <dt>prevcommand</dt>
        <dd>
            <p>Select / highlight the previous possible command</p>
            <p>Available on <em>context menu</em>.</p>
            <pre class="prettyprint lang-js">opt.$menu.trigger("prevcommand");</pre>
        </dd>
        <dt>nextcommand</dt>
        <dd>
            <p>Select / highlight the next possible command</p>
            <p>Available on <em>context menu</em>.</p>
            <pre class="prettyprint lang-js">opt.$menu.trigger("nextcommand");</pre>
        </dd>
        
        <dt>contextmenu:hide</dt>
        <dd>
            <p>Hide the menu</p>
            <p>Available on <em>context menu</em>.</p>
            <pre class="prettyprint lang-js">opt.$menu.trigger("contextmenu:hide");</pre>
        </dd>
        
        <dt>contextmenu:focus</dt>
        <dd>
            <p>React to a command item being focused</p>
            <p>Triggered on <em>context menu item</em> when mouse or keyboard interaction lead to a "hover state" for that command item.</p>
            <pre class="prettyprint lang-js">$(document.body).on("contextmenu:focus", ".context-menu-item", 
    function(e){ console.log("focus:", this); });</pre>
        </dd>
        
        <dt>contextmenu:blur</dt>
        <dd>
            <p>Available on each <em>context menu item</em>.</p>
            <p>Triggered on <em>context menu item</em> when mouse or keyboard interaction lead from a "hover state" to "default state" for that command item.</p>
            <pre class="prettyprint lang-js">$(document.body).on("contextmenu:blur", ".context-menu-item",
    function(e){ console.log("blur:", this); });</pre>
        </dd>
        
        <dt>keydown</dt>
        <dd>
            <p>Available on each <em>context menu item</em>.</p>
            <p>Triggered on <em>context menu item</em> when keyboard interaction could not be handled by jQuery.contextMenu.</p>
            <pre class="prettyprint lang-js">$(document.body).on("keydown", ".context-menu-item",
    function(e){ console.log("key:", e.keyCode); });</pre>
        </dd>
    </dl>
    
    <h2 id="html5-import">HTML5 &lt;menu&gt; import</h2>
    <p>considering the following HTML <code>$.contextMenu.fromMenu($('#html5menu'))</code> will return a proper <a href="#items">items</a> object
    <pre class="prettyprint lang-html">&lt;menu id=&quot;html5menu&quot; type=&quot;context&quot; style=&quot;display:none&quot;&gt;
  &lt;command label=&quot;rotate&quot; onclick=&quot;alert('rotate')&quot;&gt;
  &lt;command label=&quot;resize&quot; onclick=&quot;alert('resize')&quot;&gt;
  &lt;menu label=&quot;share&quot;&gt;
    &lt;command label=&quot;twitter&quot; onclick=&quot;alert('twitter')&quot;&gt;
    &lt;hr&gt;
    &lt;command label=&quot;facebook&quot; onclick=&quot;alert('facebook')&quot;&gt;
  &lt;/menu&gt;
&lt;/menu&gt;</pre>
    <p><code>$.contextMenu.fromMenu()</code> will properly import (and thus handle) the following elements. Everything else is imported as <code>{type: "html"}</code></p>
    <ul>
        <li>&lt;menu&gt;</li>
        <li>&lt;hr&gt;</li>
        <li>&lt;a&gt;</li>
        <li>&lt;command type=&quot;command|radio|checkbox&quot;&gt; (W3C Specification)</li>
        <li>&lt;menuitem type=&quot;command|radio|checkbox&quot;&gt; (Firefox 8)</li>
        <li>&lt;input type=&quot;text|radio|checkbox&quot;&gt;</li>
        <li>&lt;select&gt;</li>
        <li>&lt;textare&gt;</li>
        <li>&lt;label for="someId"&gt;</li>
        <li>&lt;label&gt; the text &lt;input|textarea|select&gt;</li>
    </ul>
    <p>The &lt;menu&gt; must be hidden but not removed, as all command events (clicks) are passed-thru to the original command element!</p>
    <p>Note: While the specs note &lt;option&gt;s to be renderd as regular commands, $.contextMenu will render an actual &lt;select&gt;.</p>
    
	<h2 id="html5-shiv">HTML5 &lt;menu&gt; shiv/polyfill</h2>
	<p>Engaging the HTML5 polyfill (ignoring $.contextMenu if context menus are available natively):</p>
	<pre class="prettyprint lang-js">$(function(){ $.contextMenu("html5"); });</pre>
	<p>Engaging the HTML5 polyfill (ignoring browser native implementation):</p>
	<pre class="prettyprint lang-js">$(function(){ $.contextMenu("html5", true); });</pre>

    <h2 id="ui-position">$.ui.position</h2>
    <p>
        The <a href="http://jqueryui.com/demos/position/">position utility of jQuery UI</a> makes relative positioning very simple. But the real beauty is <em>collision detection</em>, 
        allowing the contextMenu to be shown to the left side of the pointer, if there's not enough space to the right. 
        Its use is optional, if you want to shape off some more bytes by sacrificing usability: go ahead…
    </p>
    </div>
</body>
</html>